//
//  ByViewUserMessageNotify.m
//  jinpuyiyuan_ios
//
//  Created by pro on 2017/12/7.
//  Copyright © 2017年 mc. All rights reserved.
//

#import "ByViewUserMessageNotify.h"

// cell
#import "ByCellUserMessageNotify.h"

@interface ByViewUserMessageNotify()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) NSMutableArray *dataArray;
@end

@implementation ByViewUserMessageNotify
- (void)setupUI{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    self.tableView.backgroundColor = BY_TABLE_COLOR;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self addSubview:self.tableView];
    self.tableView.separatorColor = [UIColor colorWithWhite:0.90 alpha:1];
    self.tableView.separatorInset = UIEdgeInsetsMake(59, 10, 0, -10);
    [self fetchData];
}

- (void)setFrame:(CGRect)frame{
    [super setFrame:frame];
    self.tableView.frame = CGRectMake(0, 0, frame.size.width, frame.size.height);
}
#pragma mark - getter
- (NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}

#pragma mark - fetch data
- (void)fetchData{
    for (int i = 0; i < 10; i ++) {
        ByModelUserMessageNotify *model = [[ByModelUserMessageNotify alloc] init];
        model.title = @"系统通知";
        model.create_time = @"刚刚";
        model.content = @"这是一条系统通知系统通知系统通知系统通知";
        [self.dataArray addObject:model];
    }
    [self.tableView reloadData];
}

#pragma mark - UITableViewDataSource,UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ByCellUserMessageNotify *cell = [ByCellUserMessageNotify cellWithTableView:tableView];
    cell.model = self.dataArray[indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60;
}


@end
